﻿using UnityEditor;
using UnityEngine;

namespace EditorExtensions
{
    public class EditorGUIApi
    {
        private Rect mLabelRect = new Rect(10, 60, 200, 20);
        private Rect mTextFieldRect = new Rect(10, 90, 200, 20);
        private Rect mTextAreaRect = new Rect(10, 120, 200, 40);
        private Rect mPasswordRect = new Rect(10, 170, 200, 40);
        private Rect mDropDownButtonRect = new Rect(10, 200, 200, 20);
        private Rect mLinkedButtonRect = new Rect(10, 230, 200, 20);
        private Rect mToggleRect = new Rect(10, 260, 200, 20);
        private Rect mToggleLeftRect = new Rect(10, 290, 200, 20);
        private Rect mHelpBoxRect = new Rect(10, 320, 200, 20);
        private Rect mColorFieldRect = new Rect(10, 350, 200, 20);
        private Rect mBoundFieldRect = new Rect(10, 380, 200, 20);
        private Rect mBoundIntFieldRect = new Rect(10, 430, 200, 20);
        private Rect mCurveFieldRect = new Rect(10, 470, 200, 20);
        private Rect mDelayedDoubleFieldRect = new Rect(10, 500, 200, 20);
        private Rect mDoubleFieldRect = new Rect(10, 530, 200, 20);
        private Rect mEnumFlagsFieldRect = new Rect(10, 560, 200, 20);
        private Rect mEnumPopRect = new Rect(10, 590, 200, 20);
        private Rect mGradientFieldRect = new Rect(210, 120, 200, 20);


        private bool mDisabledGroupValue;
        private string mTextFieldValue;
        private string mTextAreaValue;
        private string mPasswordValue;
        private bool mToggleValue;
        private Color mColorValue;
        private Bounds m_BoundsValue;
        private BoundsInt m_BoundsIntValue;
        private AnimationCurve mAnimationCurveValue = new AnimationCurve();
        private double mDoubleFieldValue = 0f;
        private Gradient mGradientValue = new Gradient();


        //everything: 0 nothing : 1 
        private enum EnumFlags
        {
            A = 2,
            B,
            C,
        }

        private EnumFlags mEnumFlagsValue;
        private bool mFoldOutValue = true;

        public void Draw()
        {
            mDisabledGroupValue = EditorGUILayout.Toggle("DisabledGroup", mDisabledGroupValue);
            mFoldOutValue = EditorGUI.Foldout(new Rect(210, 80, 300, 20), mFoldOutValue, "折叠");
            if (mFoldOutValue)
            {
                EditorGUI.BeginDisabledGroup(mDisabledGroupValue == false);
                {
                    EditorGUI.LabelField(mLabelRect, "LabelField");
                    mTextFieldValue = EditorGUI.TextField(mTextFieldRect, mTextFieldValue);
                    mTextAreaValue = EditorGUI.TextArea(mTextAreaRect, mTextAreaValue);
                    mPasswordValue = EditorGUI.PasswordField(mPasswordRect, mPasswordValue);
                    if (EditorGUI.DropdownButton(mDropDownButtonRect, new GUIContent("123456"), FocusType.Keyboard))
                    {
                        Debug.Log("DropDownButtonClicked");
                    }

                    if (EditorGUI.LinkButton(mLinkedButtonRect, new GUIContent("654321")))
                    {
                        Debug.Log("LinkedButtonClicked");
                    }

                    mToggleValue = EditorGUI.Toggle(mToggleRect, mToggleValue);
                    mToggleValue = EditorGUI.ToggleLeft(mToggleLeftRect, "打开/关闭", mToggleValue);

                    EditorGUI.HelpBox(mHelpBoxRect, "error", MessageType.Error);
                    mColorValue = EditorGUI.ColorField(mColorFieldRect, mColorValue);
                    m_BoundsValue = EditorGUI.BoundsField(mBoundFieldRect, m_BoundsValue);
                    m_BoundsIntValue = EditorGUI.BoundsIntField(mBoundIntFieldRect, m_BoundsIntValue);
                    mAnimationCurveValue = EditorGUI.CurveField(mCurveFieldRect, mAnimationCurveValue);
                    mDoubleFieldValue = EditorGUI.DelayedDoubleField(mDelayedDoubleFieldRect, mDoubleFieldValue);
                    mDoubleFieldValue = EditorGUI.DoubleField(mDoubleFieldRect, mDoubleFieldValue);
                    mEnumFlagsValue = (EnumFlags)EditorGUI.EnumFlagsField(mEnumFlagsFieldRect, mEnumFlagsValue);
                    mEnumFlagsValue = (EnumFlags)EditorGUI.EnumPopup(mEnumPopRect, mEnumFlagsValue);
                    mGradientValue = EditorGUI.GradientField(mGradientFieldRect, mGradientValue);
                }
                EditorGUI.EndDisabledGroup();
            }
        }
    }
}